Python + mod_wsgi
2015/08/03 |
Install mod_wsgi (WSGI : Web Server Gateway Interface) to make Python scripts be fast.
|
|
[1] | Install mod_wsgi. |
[root@www ~]# yum -y install mod_wsgi
|
[2] | For example, configure mod_wsgi that it's possible to access to /test_wsgi that backend is /var/www/html/test_wsgi.py. |
[root@www ~]#
vi /etc/httpd/conf.d/wsgi.conf # create new
WSGIScriptAlias /test_wsgi /var/www/html/test_wsgi.py
systemctl restart httpd |
[3] | Create a test script which you set above. |
[root@www ~]#
vi /var/www/html/test_wsgi.py # create new def application(environ,start_response): status = '200 OK' html = '<html>\n' \ '<body>\n' \ '<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">\n' \ 'mod_wsgi Test Page\n' \ '</div>\n' \ '</body>\n' \ '</html>\n' response_header = [('Content-type','text/html')] start_response(status,response_header) return [html] |
[4] | Configure if you use Django. (
refer to installing Django ) For exmaple, configure "testapp" under the "/home/cent/venv/testproject" which is owned by "cent". |
[root@www ~]#
vi /etc/httpd/conf.d/django.conf # create new WSGIDaemonProcess testapp python-path=/home/cent/venv/testproject:/home/cent/venv/lib/python2.7/site-packages WSGIProcessGroup testapp WSGIScriptAlias /django /home/cent/venv/testproject/testproject/wsgi.py <Directory /home/cent/venv/testproject> Require all granted </Directory> systemctl restart httpd |